home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / dsp / dspkgctr.z / dspkgctr / gcc / recog.c < prev    next >
C/C++ Source or Header  |  1992-06-08  |  29KB  |  1,112 lines

  1. /* Subroutines used by or related to instruction recognition.
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.  
  4.    $Id: recog.c,v 1.2 91/08/06 09:57:11 jeff Exp $
  5.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 1, or (at your option)
  11. any later version.
  12.  
  13. GNU CC is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with GNU CC; see the file COPYING.  If not, write to
  20. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22.  
  23. #include "config.h"
  24. #include "rtl.h"
  25. #include <stdio.h>
  26. #if ! defined( _INTELC32_ )
  27. #include "insn-config.h"
  28. #else
  29. #include "iconfig.h"
  30. #endif
  31. #include "recog.h"
  32. #include "regs.h"
  33. #if ! defined( _INTELC32_ )
  34. #include "hard-reg-set.h"
  35. #else
  36. #include "hardrset.h"
  37. #endif
  38. #include "real.h"
  39.  
  40.  
  41. static int inequality_comparisons_p ();
  42. int strict_memory_address_p ();
  43. int memory_address_p ();
  44.  
  45. /* Nonzero means allow operands to be volatile.
  46.    This is 1 if you use recog_memoized, 0 if you don't.
  47.    init_recog and recog_memoized are responsible for setting it.
  48.    This way of handling it is not really clean and will be change later.  */
  49.  
  50. int volatile_ok;
  51.  
  52. rtx recog_addr_dummy;
  53.  
  54. /* On return from `constrain_operands', indicate which alternative
  55.    was satisfied.  */
  56.  
  57. int which_alternative;
  58.  
  59. /* Nonzero after end of reload pass.
  60.    Set to 1 or 0 by toplev.c.
  61.    Controls the significance of (SUBREG (MEM)).  */
  62.  
  63. int reload_completed;
  64.  
  65. /* Initialize data used by the function `recog'.
  66.    This must be called once in the compilation of a function
  67.    before any insn recognition may be done in the function.  */
  68.  
  69. void
  70. init_recog ()
  71. {
  72.   volatile_ok = 0;
  73.   recog_addr_dummy = gen_rtx (MEM, VOIDmode, 0);
  74. }
  75.  
  76. /* Try recognizing the instruction INSN,
  77.    and return the code number that results.
  78.    Remeber the code so that repeated calls do not
  79.    need to spend the time for actual rerecognition.
  80.  
  81.    This function is the normal interface to instruction recognition.
  82.    The automatically-generated function `recog' is normally called
  83.    through this one.  (The only exception is in combine.c.)  */
  84.  
  85. int
  86. recog_memoized (insn)
  87.      rtx insn;
  88. {
  89.   volatile_ok = 1;
  90.   if (INSN_CODE (insn) < 0)
  91.     INSN_CODE (insn) = recog (PATTERN (insn), insn);
  92.   return INSN_CODE (insn);
  93. }
  94.  
  95. /* Return 1 if the insn following INSN does not contain
  96.    any ordered tests applied to the condition codes.
  97.    EQ and NE tests do not count.  */
  98.  
  99. int
  100. next_insn_tests_no_inequality (insn)
  101.      rtx insn;
  102. {
  103.   register rtx next = NEXT_INSN (insn);
  104.  
  105.   return ((GET_CODE (next) == JUMP_INSN
  106.        || GET_CODE (next) == INSN
  107.        || GET_CODE (next) == CALL_INSN)
  108.       && ! inequality_comparisons_p (PATTERN (next)));
  109. }
  110.  
  111. /* Return 1 if the CC value set up by INSN is not used.  */
  112.  
  113. int
  114. next_insns_test_no_inequality (insn)
  115.      rtx insn;
  116. {
  117.   register rtx next = NEXT_INSN (insn);
  118.  
  119.   for (; next != 0; next = NEXT_INSN (next))
  120.     {
  121.       if (GET_CODE (next) == CODE_LABEL
  122.       || GET_CODE (next) == BARRIER)
  123.     return 1;
  124.       if (GET_CODE (next) == NOTE)
  125.     continue;
  126.       if (inequality_comparisons_p (PATTERN (next)))
  127.     return 0;
  128.       if (GET_CODE (PATTERN (next)) == SET
  129.       && SET_DEST (PATTERN (next)) == cc0_rtx)
  130.     return 1;
  131.       if (! reg_mentioned_p (cc0_rtx, PATTERN (next)))
  132.     return 1;
  133.     }
  134.   return 1;
  135. }
  136.  
  137. static int
  138. inequality_comparisons_p (x)
  139.      rtx x;
  140. {
  141.   register char *fmt;
  142.   register int len, i;
  143.   register enum rtx_code code = GET_CODE (x);
  144.  
  145.   switch (code)
  146.     {
  147.     case REG:
  148.     case PC:
  149.     case CC0:
  150.     case CONST_INT:
  151.     case CONST_DOUBLE:
  152.     case CONST:
  153.     case LABEL_REF:
  154.     case SYMBOL_REF:
  155.       return 0;
  156.  
  157.     case LT:
  158.     case LTU:
  159.     case GT:
  160.     case GTU:
  161.     case LE:
  162.     case LEU:
  163.     case GE:
  164.     case GEU:
  165.       return (XEXP (x, 0) == cc0_rtx || XEXP (x, 1) == cc0_rtx);
  166.     }
  167.  
  168.   len = GET_RTX_LENGTH (code);
  169.   fmt = GET_RTX_FORMAT (code);
  170.  
  171.   for (i = 0; i < len; i++)
  172.     {
  173.       if (fmt[i] == 'e')
  174.     {
  175.       if (inequality_comparisons_p (XEXP (x, i)))
  176.         return 1;
  177.     }
  178.       else if (fmt[i] == 'E')
  179.     {
  180.       register int j;
  181.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  182.         if (inequality_comparisons_p (XVECEXP (x, i, j)))
  183.           return 1;
  184.     }
  185.     }
  186.         
  187.   return 0;
  188. }
  189.  
  190. /* Return 1 if OP is a valid general operand for machine mode MODE.
  191.    This is either a register reference, a memory reference,
  192.    or a constant.  In the case of a memory reference, the address
  193.    is checked for general validity for the target machine.
  194.  
  195.    Register and memory references must have mode MODE in order to be valid,
  196.    but some constants have no machine mode and are valid for any mode.
  197.  
  198.    If MODE is VOIDmode, OP is checked for validity for whatever mode
  199.    it has.
  200.  
  201.    The main use of this function is as a predicate in match_operand
  202.    expressions in the machine description.  */
  203.  
  204. int
  205. general_operand (op, mode)
  206.      register rtx op;
  207.      enum machine_mode mode;
  208. {
  209.   register enum rtx_code code = GET_CODE (op);
  210.   int mode_altering_drug = 0;
  211.  
  212.   if (mode == VOIDmode)
  213.     mode = GET_MODE (op);
  214.  
  215.   if (CONSTANT_P (op))
  216.     return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode)
  217.         && LEGITIMATE_CONSTANT_P (op));
  218.  
  219.   /* Except for certain constants with VOIDmode, already checked for,
  220.      OP's mode must match MODE if MODE specifies a mode.  */
  221.  
  222.   if (GET_MODE (op) != mode)
  223.     return 0;
  224.  
  225.   while (code == SUBREG)
  226.     {
  227.       op = SUBREG_REG (op);
  228.       code = GET_CODE (op);
  229. #if 0
  230.       /* No longer needed, since (SUBREG (MEM...))
  231.      will load the MEM into a reload reg in the MEM's own mode.  */
  232.       mode_altering_drug = 1;
  233. #endif
  234.     }
  235.   if (code == REG)
  236.     return 1;
  237.   if (code == CONST_DOUBLE)
  238.     return LEGITIMATE_CONSTANT_P (op);
  239.   if (code == MEM)
  240.     {
  241.       register rtx y = XEXP (op, 0);
  242.       if (! volatile_ok && MEM_VOLATILE_P (op))
  243.     return 0;
  244.       /* Use the mem's mode, since it will be reloaded thus.  */
  245.       mode = GET_MODE (op);
  246.       GO_IF_LEGITIMATE_ADDRESS (mode, y, win);
  247.     }
  248.   return 0;
  249.  
  250.  win:
  251.   if (mode_altering_drug)
  252.     return ! mode_dependent_address_p (XEXP (op, 0));
  253.   return 1;
  254. }
  255.  
  256. /* Return 1 if OP is a valid memory address for a memory reference
  257.    of mode MODE.
  258.  
  259.    The main use of this function is as a predicate in match_operand
  260.    expressions in the machine description.  */
  261.  
  262. int
  263. address_operand (op, mode)
  264.      register rtx op;
  265.      enum machine_mode mode;
  266. {
  267.   return memory_address_p (mode, op);
  268. }
  269.  
  270. /* Return 1 if OP is a register reference of mode MODE.
  271.    If MODE is VOIDmode, accept a register in any mode.
  272.  
  273.    The main use of this function is as a predicate in match_operand
  274.    expressions in the machine description.  */
  275.  
  276. int
  277. register_operand (op, mode)
  278.      register rtx op;
  279.      enum machine_mode mode;
  280. {
  281.   if (GET_MODE (op) != mode && mode != VOIDmode)
  282.     return 0;
  283.  
  284.   if (GET_CODE (op) == SUBREG)
  285.     {
  286.       /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
  287.      because it is guaranteed to be reloaded into one.
  288.      Just make sure the MEM is valid in itself.
  289.      (Ideally, (SUBREG (MEM)...) should not exist after reload,
  290.      but currently it does result from (SUBREG (REG)...) where the
  291.      reg went on the stack.)  */
  292.       if (! reload_completed)
  293.     return general_operand (op, mode);
  294.     }
  295.  
  296.   while (GET_CODE (op) == SUBREG)
  297.     op = SUBREG_REG (op);
  298.  
  299.   return GET_CODE (op) == REG;
  300. }
  301.  
  302. /* Return 1 if OP is a valid immediate operand for mode MODE.
  303.  
  304.    The main use of this function is as a predicate in match_operand
  305.    expressions in the machine description.  */
  306.  
  307. int
  308. immediate_operand (op, mode)
  309.      register rtx op;
  310.      enum machine_mode mode;
  311. {
  312.   return ((CONSTANT_P (op)
  313.        || (GET_CODE (op) == CONST_DOUBLE
  314.            && (GET_MODE (op) == mode || mode == VOIDmode)))
  315.       && LEGITIMATE_CONSTANT_P (op));
  316. }
  317.  
  318. /* Return 1 if OP is a general operand that is not an immediate operand.  */
  319.  
  320. int
  321. nonimmediate_operand (op, mode)
  322.      register rtx op;
  323.      enum machine_mode mode;
  324. {
  325.   return (general_operand (op, mode)
  326.       && ! CONSTANT_P (op) && GET_CODE (op) != CONST_DOUBLE);
  327. }
  328.  
  329. /* Return 1 if OP is a register reference or immediate value of mode MODE.  */
  330.  
  331. int
  332. nonmemory_operand (op, mode)
  333.      register rtx op;
  334.      enum machine_mode mode;
  335. {
  336.   if (CONSTANT_P (op) || GET_CODE (op) == CONST_DOUBLE)
  337.     return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode)
  338.         && LEGITIMATE_CONSTANT_P (op));
  339.  
  340.   if (GET_MODE (op) != mode && mode != VOIDmode)
  341.     return 0;
  342.  
  343.   if (GET_CODE (op) == SUBREG)
  344.     {
  345.       /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
  346.      because it is guaranteed to be reloaded into one.
  347.      Just make sure the MEM is valid in itself.
  348.      (Ideally, (SUBREG (MEM)...) should not exist after reload,
  349.      but currently it does result from (SUBREG (REG)...) where the
  350.      reg went on the stack.)  */
  351.       if (! reload_completed)
  352.     return general_operand (op, mode);
  353.     }
  354.  
  355.   while (GET_CODE (op) == SUBREG)
  356.     op = SUBREG_REG (op);
  357.  
  358.   return GET_CODE (op) == REG;
  359. }
  360.  
  361. /* Return 1 if OP is a valid operand that stands for pushing a
  362.    value of mode MODE onto the stack.
  363.  
  364.    The main use of this function is as a predicate in match_operand
  365.    expressions in the machine description.  */
  366.  
  367. int
  368. push_operand (op, mode)
  369.      rtx op;
  370.      enum machine_mode mode;
  371. {
  372.   if (GET_CODE (op) != MEM)
  373.     return 0;
  374.  
  375.   if (GET_MODE (op) != mode)
  376.     return 0;
  377.  
  378.   op = XEXP (op, 0);
  379.  
  380. #ifdef STACK_GROWS_DOWNWARD
  381.   if (GET_CODE (op) != PRE_DEC)
  382.     return 0;
  383. #else
  384.   if (GET_CODE (op) != PRE_INC)
  385.     return 0;
  386. #endif
  387.   return XEXP (op, 0) == stack_pointer_rtx;
  388. }
  389.  
  390. /* Return 1 if ADDR is a valid memory address for mode MODE.  */
  391.  
  392. int
  393. memory_address_p (mode, addr)
  394.      enum machine_mode mode;
  395.      register rtx addr;
  396. {
  397.   GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
  398.   return 0;
  399.  
  400.  win:
  401.   return 1;
  402. }
  403.  
  404. /* Return 1 if OP is a valid memory reference with mode MODE,
  405.    including a valid address.
  406.  
  407.    The main use of this function is as a predicate in match_operand
  408.    expressions in the machine description.  */
  409.  
  410. int
  411. memory_operand (op, mode)
  412.      register rtx op;
  413.      enum machine_mode mode;
  414. {
  415.   rtx inner;
  416.   int mode_altering_drug = 0;
  417.  
  418.   if (! reload_completed)
  419.     /* Note that no SUBREG is a memory operand before end of reload pass,
  420.        because (SUBREG (MEM...)) forces reloading into a register.  */
  421.     return GET_CODE (op) == MEM && general_operand (op, mode);
  422.  
  423.   if (mode != VOIDmode && GET_MODE (op) != mode)
  424.     return 0;
  425.  
  426.   inner = op;
  427.   while (GET_CODE (inner) == SUBREG)
  428.     inner = SUBREG_REG (inner);
  429.  
  430.   return (GET_CODE (inner) == MEM && general_operand (op, mode));
  431. }
  432.  
  433. /* Return 1 if OP is a valid indirect memory reference with mode MODE;
  434.    that is, a memory reference whose address is a general_operand.  */
  435.  
  436. int
  437. indirect_operand (op, mode)
  438.      register rtx op;
  439.      enum machine_mode mode;
  440. {
  441.   return (GET_MODE (op) == mode && memory_operand (op, mode)
  442.       && general_operand (XEXP (op, 0), Pmode));
  443. }
  444.  
  445. /* If BODY is an insn body that uses ASM_OPERANDS,
  446.    return the number of operands (both input and output) in the insn.
  447.    Otherwise return -1.  */
  448.  
  449. int
  450. asm_noperands (body)
  451.      rtx body;
  452. {
  453.   if (GET_CODE (body) == ASM_OPERANDS)
  454.     /* No output operands: return number of input operands.  */
  455.     return XVECLEN (body, 3);
  456.   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
  457.     /* Single output operand: BODY is (set OUTPUT (asm_operands ...)).  */
  458.     return XVECLEN (SET_SRC (body), 3) + 1;
  459.   else if (GET_CODE (body) == PARALLEL
  460.        && GET_CODE (XVECEXP (body, 0, 0)) == SET
  461.        && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
  462.     {
  463.       /* Multiple output operands, or 1 output plus some clobbers:
  464.      body is [(set OUTPUT (asm_operands ...))... (clobber (reg ...))...].  */
  465.       int i;
  466.       int n_sets;
  467.  
  468.       /* Count backwards through CLOBBERs to determine number of SETs.  */
  469.       for (i = XVECLEN (body, 0); i > 0; i--)
  470.     {
  471.       if (GET_CODE (XVECEXP (body, 0, i - 1)) == SET)
  472.         break;
  473.       if (GET_CODE (XVECEXP (body, 0, i - 1)) != CLOBBER)
  474.         return -1;
  475.     }
  476.  
  477.       /* N_SETS is now number of output operands.  */
  478.       n_sets = i;
  479.  
  480.       /* Verify that all the SETs we have
  481.      came from a single original asm_operands insn
  482.      (so that invalid combinations are blocked).  */
  483.       for (i = 0; i < n_sets; i++)
  484.     {
  485.       rtx elt = XVECEXP (body, 0, i);
  486.       if (GET_CODE (elt) != SET)
  487.         return -1;
  488.       if (GET_CODE (SET_SRC (elt)) != ASM_OPERANDS)
  489.         return -1;
  490.       /* If these ASM_OPERANDS rtx's came from different original insns
  491.          then they aren't allowed together.  */
  492.       if (XVEC (SET_SRC (elt), 3)
  493.           != XVEC (SET_SRC (XVECEXP (body, 0, 0)), 3))
  494.         return -1;
  495.     }
  496.       return XVECLEN (SET_SRC (XVECEXP (body, 0, 0)), 3) + n_sets;
  497.     }
  498.   else if (GET_CODE (body) == PARALLEL
  499.        && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
  500.     {
  501.       /* 0 outputs, but some clobbers:
  502.      body is [(asm_operands ...) (clobber (reg ...))...].  */
  503.       int i;
  504.       int n_sets;
  505.  
  506.       /* Make sure all the other parallel things really are clobbers.  */
  507.       for (i = XVECLEN (body, 0) - 1; i > 0; i--)
  508.     if (GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
  509.       return -1;
  510.  
  511.       return XVECLEN (XVECEXP (body, 0, 0), 3);
  512.     }
  513.   else
  514.     return -1;
  515. }
  516.  
  517. /* Assuming BODY is an insn body that uses ASM_OPERANDS,
  518.    copy its operands (both input and output) into the vector OPERANDS,
  519.    the locations of the operands within the insn into the vector OPERAND_LOCS,
  520.    and the constraints for the operands into CONSTRAINTS.
  521.    Write the modes of the operands into MODES.
  522.    Return the assembler-template.
  523.  
  524.    If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
  525.    we don't store that info.  */
  526.  
  527. char *
  528. decode_asm_operands (body, operands, operand_locs, constraints, modes)
  529.      rtx body;
  530.      rtx *operands;
  531.      rtx **operand_locs;
  532.      char **constraints;
  533.      enum machine_mode *modes;
  534. {
  535.   register int i;
  536.   int noperands;
  537.   char *template = 0;
  538.  
  539.   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
  540.     {
  541.       rtx asmop = SET_SRC (body);
  542.       /* Single output operand: BODY is (set OUTPUT (asm_operands ....)).  */
  543.  
  544.       noperands = XVECLEN (asmop, 3) + 1;
  545.  
  546.       /* The input operands are found in the 1st element vector.  */
  547.       /* Constraints for inputs are in the 2nd element vector.  */
  548.       for (i = 1; i < noperands; i++)
  549.     {
  550.       if (operand_locs)
  551.         operand_locs[i] = &XVECEXP (asmop, 3, i - 1);
  552.       if (operands)
  553.         operands[i] = XVECEXP (asmop, 3, i - 1);
  554.       if (constraints)
  555.         constraints[i] = XSTR (XVECEXP (asmop, 4, i - 1), 0);
  556.       if (modes)
  557.         modes[i] = GET_MODE (XVECEXP (asmop, 4, i - 1));
  558.     }
  559.  
  560.       /* The output is in the SET.
  561.      Its constraint is in the ASM_OPERANDS itself.  */
  562.       if (operands)
  563.     operands[0] = SET_DEST (body);
  564.       if (operand_locs)
  565.     operand_locs[0] = &SET_DEST (body);
  566.       if (constraints)
  567.     constraints[0] = XSTR (asmop, 1);
  568.       if (modes)
  569.     modes[0] = GET_MODE (SET_DEST (body));
  570.       template = XSTR (asmop, 0);
  571.     }
  572.   else if (GET_CODE (body) == ASM_OPERANDS)
  573.     {
  574.       rtx asmop = body;
  575.       /* No output operands: BODY is (asm_operands ....).  */
  576.  
  577.       noperands = XVECLEN (asmop, 3);
  578.  
  579.       /* The input operands are found in the 1st element vector.  */
  580.       /* Constraints for inputs are in the 2nd element vector.  */
  581.       for (i = 0; i < noperands; i++)
  582.     {
  583.       if (operand_locs)
  584.         operand_locs[i] = &XVECEXP (asmop, 3, i);
  585.       if (operands)
  586.         operands[i] = XVECEXP (asmop, 3, i);
  587.       if (constraints)
  588.         constraints[i] = XSTR (XVECEXP (asmop, 4, i), 0);
  589.       if (modes)
  590.         modes[i] = GET_MODE (XVECEXP (asmop, 4, i));
  591.     }
  592.       template = XSTR (asmop, 0);
  593.     }
  594.   else if (GET_CODE (body) == PARALLEL
  595.        && GET_CODE (XVECEXP (body, 0, 0)) == SET)
  596.     {
  597.       rtx asmop = SET_SRC (XVECEXP (body, 0, 0));
  598.       int nparallel = XVECLEN (body, 0); /* Includes CLOBBERs.  */
  599.       int nin = XVECLEN (asmop, 3);
  600.       int nout = 0;        /* Does not include CLOBBERs.  */
  601.  
  602.       /* At least one output, plus some CLOBBERs.  */
  603.  
  604.       /* The outputs are in the SETs.
  605.      Their constraints are in the ASM_OPERANDS itself.  */
  606.       for (i = 0; i < nparallel; i++)
  607.     {
  608.       if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
  609.         break;        /* Past last SET */
  610.       
  611.       if (operands)
  612.         operands[i] = SET_DEST (XVECEXP (body, 0, i));
  613.       if (operand_locs)
  614.         operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
  615.       if (constraints)
  616.         constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
  617.       if (modes)
  618.         modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
  619.       nout++;
  620.     }
  621.  
  622.       /* The input operands are found in the 1st element vector.  */
  623.       /* Constraints for inputs are in the 2nd element vector.  */
  624.       for (i = 0; i < nin; i++)
  625.     {
  626.       if (operand_locs)
  627.         operand_locs[i + nout] = &XVECEXP (asmop, 3, i);
  628.       if (operands)
  629.         operands[i + nout] = XVECEXP (asmop, 3, i);
  630.       if (constraints)
  631.         constraints[i + nout] = XSTR (XVECEXP (asmop, 4, i), 0);
  632.       if (modes)
  633.         modes[i + nout] = GET_MODE (XVECEXP (asmop, 4, i));
  634.     }
  635.  
  636.       template = XSTR (asmop, 0);
  637.     }
  638.   else if (GET_CODE (body) == PARALLEL
  639.        && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
  640.     {
  641.       /* No outputs, but some CLOBBERs.  */
  642.  
  643.       rtx asmop = XVECEXP (body, 0, 0);
  644.       int nin = XVECLEN (asmop, 3);
  645.  
  646.       /* The input operands are found in the 1st element vector.  */
  647.       /* Constraints for inputs are in the 2nd element vector.  */
  648.       for (i = 0; i < nin; i++)
  649.     {
  650.       if (operand_locs)
  651.         operand_locs[i] = &XVECEXP (asmop, 3, i);
  652.       if (operands)
  653.         operands[i] = XVECEXP (asmop, 3, i);
  654.       if (constraints)
  655.         constraints[i] = XSTR (XVECEXP (asmop, 4, i), 0);
  656.       if (modes)
  657.         modes[i] = GET_MODE (XVECEXP (asmop, 4, i));
  658.     }
  659.  
  660.       template = XSTR (asmop, 0);
  661.     }
  662.  
  663.   return template;
  664. }
  665.  
  666. extern rtx plus_constant ();
  667. extern rtx copy_rtx ();
  668.  
  669. /* Given an rtx *P, if it is a sum containing an integer constant term,
  670.    return the location (type rtx *) of the pointer to that constant term.
  671.    Otherwise, return a null pointer.  */
  672.  
  673. static rtx *
  674. find_constant_term_loc (p)
  675.      rtx *p;
  676. {
  677.   register rtx *tem;
  678.   register enum rtx_code code = GET_CODE (*p);
  679.  
  680.   /* If *P IS such a constant term, P is its location.  */
  681.  
  682.   if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
  683.       || code == CONST)
  684.     return p;
  685.  
  686.   /* Otherwise, if not a sum, it has no constant term.  */
  687.  
  688.   if (GET_CODE (*p) != PLUS)
  689.     return 0;
  690.  
  691.   /* If one of the summands is constant, return its location.  */
  692.  
  693.   if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
  694.       && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
  695.     return p;
  696.  
  697.   /* Otherwise, check each summand for containing a constant term.  */
  698.  
  699.   if (XEXP (*p, 0) != 0)
  700.     {
  701.       tem = find_constant_term_loc (&XEXP (*p, 0));
  702.       if (tem != 0)
  703.     return tem;
  704.     }
  705.  
  706.   if (XEXP (*p, 1) != 0)
  707.     {
  708.       tem = find_constant_term_loc (&XEXP (*p, 1));
  709.       if (tem != 0)
  710.     return tem;
  711.     }
  712.  
  713.   return 0;
  714. }
  715.  
  716. /* Return 1 if OP is a memory reference
  717.    whose address contains no side effects
  718.    and remains valid after the addition
  719.    of a positive integer less than the
  720.    size of the object being referenced.
  721.  
  722.    We assume that the original address is valid and do not check it.
  723.  
  724.    This uses strict_memory_address_p as a subroutine, so
  725.    don't use it before reload.  */
  726.  
  727. int
  728. offsettable_memref_p (op)
  729.      rtx op;
  730. {
  731.   return ((GET_CODE (op) == MEM)
  732.       && offsettable_address_p (1, GET_MODE (op), XEXP (op, 0)));
  733. }
  734.  
  735. /* Return 1 if Y is a memory address which contains no side effects
  736.    and would remain valid for mode MODE
  737.    after the addition of a positive integer less than the
  738.    size of that mode.
  739.  
  740.    We assume that the original address is valid and do not check it.
  741.  
  742.    If STRICTP is nonzero, we require a strictly valid address,
  743.    for the sake of use in reload.c.  */
  744.  
  745. int
  746. offsettable_address_p (strictp, mode, y)
  747.      int strictp;
  748.      enum machine_mode mode;
  749.      register rtx y;
  750. {
  751.   register enum rtx_code ycode = GET_CODE (y);
  752.   register rtx z;
  753.   rtx y1 = y;
  754.   rtx *y2;
  755.   int (*addressp) () = (strictp ? strict_memory_address_p : memory_address_p);
  756.  
  757.   if (CONSTANT_ADDRESS_P (y))
  758.     return 1;
  759.       
  760.   /* If the expression contains a constant term,
  761.      see if it remains valid when max possible offset is added.  */
  762.  
  763.   if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
  764.     {
  765.       int old = INTVAL (y1 = *y2);
  766.       int good;
  767.       INTVAL (y1) += GET_MODE_SIZE (mode) - 1;
  768.       good = (*addressp) (mode, y);
  769.       /* In any case, restore old contents of memory.  */
  770.       INTVAL (y1) = old;
  771.       return good;
  772.     }
  773.  
  774.   if (ycode == PRE_DEC || ycode == PRE_INC
  775.       || ycode == POST_DEC || ycode == POST_INC)
  776.     return 0;
  777.  
  778.   /* The offset added here is chosen as the maximum offset that
  779.      any instruction could need to add when operating on something
  780.      of the specified mode.  We assume that if Y and Y+c are
  781.      valid addresses then so is Y+d for all 0<d<c.  */
  782.  
  783.   z = plus_constant (y, GET_MODE_SIZE (mode) - 1);
  784.  
  785.   return (*addressp) (mode, z);
  786. }
  787.  
  788. /* Return 1 if ADDR is an address-expression whose effect depends
  789.    on the mode of the memory reference it is used in.
  790.  
  791.    Autoincrement addressing is a typical example of mode-dependence
  792.    because the amount of the increment depends on the mode.  */
  793.  
  794. int
  795. mode_dependent_address_p (addr)
  796.      rtx addr;
  797. {
  798.   GO_IF_MODE_DEPENDENT_ADDRESS (addr, win);
  799.   return 0;
  800.  win:
  801.   return 1;
  802. }
  803.  
  804. /* Return 1 if OP is a general operand
  805.    other than a memory ref with a mode dependent address.  */
  806.  
  807. int
  808. mode_independent_operand (op, mode)
  809.      enum machine_mode mode;
  810.      rtx op;
  811. {
  812.   rtx addr;
  813.  
  814.   if (! general_operand (op, mode))
  815.     return 0;
  816.  
  817.   if (GET_CODE (op) != MEM)
  818.     return 1;
  819.  
  820.   addr = XEXP (op, 0);
  821.   GO_IF_MODE_DEPENDENT_ADDRESS (addr, lose);
  822.   return 1;
  823.  lose:
  824.   return 0;
  825. }
  826.  
  827. /* Given an operand OP that is a valid memory reference
  828.    which satisfies offsettable_memref_p,
  829.    return a new memory reference whose address has been adjusted by OFFSET.
  830.    OFFSET should be positive and less than the size of the object referenced.
  831. */
  832.  
  833. rtx
  834. adj_offsettable_operand (op, offset)
  835.      rtx op;
  836.      int offset;
  837. {
  838.   register enum rtx_code code = GET_CODE (op);
  839.  
  840.   if (code == MEM) 
  841.     {
  842.       register rtx y = XEXP (op, 0);
  843.  
  844.       if (CONSTANT_ADDRESS_P (y))
  845.     return gen_rtx (MEM, GET_MODE (op), plus_constant (y, offset));
  846.  
  847.       if (GET_CODE (y) == PLUS)
  848.     {
  849.       rtx z = y;
  850.       register rtx *const_loc;
  851.  
  852.       op = copy_rtx (op);
  853.       z = XEXP (op, 0);
  854.       const_loc = find_constant_term_loc (&z);
  855.       if (const_loc)
  856.         {
  857.           *const_loc = plus_constant (*const_loc, offset);
  858.           return op;
  859.         }
  860.     }
  861.  
  862.       return gen_rtx (MEM, GET_MODE (op), plus_constant (y, offset));
  863.     }
  864.   abort ();
  865. }
  866.  
  867. #ifdef REGISTER_CONSTRAINTS
  868.  
  869. /* Check the operands of an insn (found in recog_operands)
  870.    against the insn's operand constraints (found via INSN_CODE_NUM)
  871.    and return 1 if they are valid.
  872.  
  873.    WHICH_ALTERNATIVE is set to a number which indicates which
  874.    alternative of constraints was matched: 0 for the first alternative,
  875.    1 for the next, etc.
  876.  
  877.    In addition, when two operands are match
  878.    and it happens that the output operand is (reg) while the
  879.    input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
  880.    make the output operand look like the input.
  881.    This is because the output operand is the one the template will print.
  882.  
  883.    This is used in final, just before printing the assembler code.  */
  884.  
  885. struct funny_match
  886. {
  887.   int this, other;
  888. };
  889.  
  890. int
  891. constrain_operands (insn_code_num)
  892.      int insn_code_num;
  893. {
  894.   char *constraints[MAX_RECOG_OPERANDS];
  895.   register int c;
  896.   int noperands = insn_n_operands[insn_code_num];
  897.  
  898.   struct funny_match funny_match[MAX_RECOG_OPERANDS];
  899.   int funny_match_index;
  900.   int nalternatives = insn_n_alternatives[insn_code_num];
  901.  
  902.   if (noperands == 0 || nalternatives == 0)
  903.     return 1;
  904.  
  905.   for (c = 0; c < noperands; c++)
  906.     constraints[c] = insn_operand_constraint[insn_code_num][c];
  907.  
  908.   which_alternative = 0;
  909.  
  910.   while (which_alternative < nalternatives)
  911.     {
  912.       register int opno;
  913.       int lose = 0;
  914.       funny_match_index = 0;
  915.  
  916.       for (opno = 0; opno < noperands; opno++)
  917.     {
  918.       register rtx op = recog_operand[opno];
  919.       register char *p = constraints[opno];
  920.       int win = 0;
  921.       int val;
  922.  
  923.       /* `alter_subreg' should already have converted any SUBREG
  924.          that appears at the level of an operand.  */
  925.       while (GET_CODE (op) == SUBREG)
  926.         abort ();
  927.  
  928.       /* An empty constraint or empty alternative
  929.          allows anything which matched the pattern.  */
  930.       if (*p == 0 || *p == ',')
  931.         win = 1;
  932.  
  933.       while (*p && (c = *p++) != ',')
  934.         switch (c)
  935.           {
  936.           case '=':
  937.           case '+':
  938.           case '?':
  939.           case '#':
  940.           case '&':
  941.           case '!':
  942.           case '*':
  943.           case '%':
  944.         break;
  945.  
  946.           case '0':
  947.           case '1':
  948.           case '2':
  949.           case '3':
  950.           case '4':
  951.         /* This operand must be the same as a previous one.  */
  952.         /* This kind of constraint is used for instructions such
  953.            as add when they take only two operands.  */
  954.         /* Note that the lower-numbered operand is passed first.  */
  955.         val = operands_match_p (recog_operand[c - '0'],
  956.                     recog_operand[opno]);
  957.         if (val != 0)
  958.           win = 1;
  959.         /* If output is *x and input is *--x,
  960.            arrange later to change the output to *--x as well,
  961.            since the output op is the one that will be printed.  */
  962.         if (val == 2)
  963.           {
  964.             funny_match[funny_match_index].this = opno;
  965.             funny_match[funny_match_index++].other = c - '0';
  966.           }
  967.         break;
  968.  
  969.           case 'p':
  970.         /* p is used for address_operands, and everything
  971.            that must be checked was checked already.  */
  972.         win = 1;
  973.         break;
  974.  
  975.         /* No need to check general_operand again;
  976.            it was done in insn-recog.c.  */
  977.           case 'g':
  978.         /* Anything goes unless it is a REG and really has a hard reg
  979.            but the hard reg is not in the class GENERAL_REGS.  */
  980.         if (GENERAL_REGS == ALL_REGS
  981.             || GET_CODE (op) != REG
  982.             || reg_fits_class_p (op, GENERAL_REGS, 0, GET_MODE (op)))
  983.           win = 1;
  984.         break;
  985.  
  986.           case 'r':
  987.         if (GET_CODE (op) == REG
  988.             && (GENERAL_REGS == ALL_REGS
  989.             || reg_fits_class_p (op, GENERAL_REGS, 0, GET_MODE (op))))
  990.           win = 1;
  991.         break;
  992.  
  993.           case 'm':
  994.         if (GET_CODE (op) == MEM)
  995.           win = 1;
  996.         break;
  997.  
  998.           case '<':
  999.         if (GET_CODE (op) == MEM
  1000.             && (GET_CODE (XEXP (op, 0)) == PRE_DEC
  1001.             || GET_CODE (XEXP (op, 0)) == POST_DEC))
  1002.           win = 1;
  1003.         break;
  1004.  
  1005.           case '>':
  1006.         if (GET_CODE (op) == MEM
  1007.             && (GET_CODE (XEXP (op, 0)) == PRE_INC
  1008.             || GET_CODE (XEXP (op, 0)) == POST_INC))
  1009.           win = 1;
  1010.         break;
  1011.  
  1012.           case 'F':
  1013.         if (GET_CODE (op) == CONST_DOUBLE)
  1014.           win = 1;
  1015.         break;
  1016.  
  1017.           case 'G':
  1018.           case 'H':
  1019.         if (GET_CODE (op) == CONST_DOUBLE
  1020.             && CONST_DOUBLE_OK_FOR_LETTER_P (op, c))
  1021.           win = 1;
  1022.         break;
  1023.  
  1024.           case 's':
  1025.         if (GET_CODE (op) == CONST_INT)
  1026.           break;
  1027.           case 'i':
  1028.         if (CONSTANT_P (op))
  1029.           win = 1;
  1030.         break;
  1031.  
  1032.           case 'n':
  1033.         if (GET_CODE (op) == CONST_INT)
  1034.           win = 1;
  1035.         break;
  1036.  
  1037.           case 'I':
  1038.           case 'J':
  1039.           case 'K':
  1040.           case 'L':
  1041.           case 'M':
  1042.         if (GET_CODE (op) == CONST_INT
  1043.             && CONST_OK_FOR_LETTER_P (INTVAL (op), c))
  1044.           win = 1;
  1045.         break;
  1046.  
  1047.           case 'o':
  1048.         if (offsettable_memref_p (op))
  1049.           win = 1;
  1050.         break;
  1051.  
  1052.           default:
  1053.         if (GET_CODE (op) == REG
  1054.             && reg_fits_class_p (op, REG_CLASS_FROM_LETTER (c),
  1055.                      0, GET_MODE (op)))
  1056.           win = 1;
  1057.           }
  1058.  
  1059.       constraints[opno] = p;
  1060.       /* If this operand did not win somehow,
  1061.          this alternative loses.  */
  1062.       if (! win)
  1063.         lose = 1;
  1064.     }
  1065.       /* This alternative won; the operands are ok.
  1066.      Change whichever operands this alternative says to change.  */
  1067.       if (! lose)
  1068.     {
  1069.       while (--funny_match_index >= 0)
  1070.         {
  1071.           recog_operand[funny_match[funny_match_index].other]
  1072.         = recog_operand[funny_match[funny_match_index].this];
  1073.         }
  1074.       return 1;
  1075.     }
  1076.  
  1077.       which_alternative++;
  1078.     }
  1079.   return 0;
  1080. }
  1081.  
  1082. /* Return 1 iff OPERAND (assumed to be a REG rtx)
  1083.    is a hard reg in class CLASS when its regno is offsetted by OFFSET
  1084.    and changed to mode MODE.
  1085.    If REG occupies multiple hard regs, all of them must be in CLASS.  */
  1086.  
  1087. int
  1088. reg_fits_class_p (operand, class, offset, mode)
  1089.      rtx operand;
  1090.      register enum reg_class class;
  1091.      int offset;
  1092.      enum machine_mode mode;
  1093. {
  1094.   register int regno = REGNO (operand);
  1095.   if (regno < FIRST_PSEUDO_REGISTER
  1096.       && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
  1097.                 regno + offset))
  1098.     {
  1099.       register int sr;
  1100.       regno += offset;
  1101.       for (sr = HARD_REGNO_NREGS (regno, mode) - 1;
  1102.        sr > 0; sr--)
  1103.     if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
  1104.                  regno + sr))
  1105.       break;
  1106.       return sr == 0;
  1107.     }
  1108.   return 0;
  1109. }
  1110.  
  1111. #endif /* REGISTER_CONSTRAINTS */
  1112.